package com.topscomm.file.task;

import java.util.List;
import java.util.Map;

import com.topscomm.file.service.IFileProcessChain;
import com.topscomm.file.service.IFileProcessFilter;

/**
 * 文件处理链
 * 
 * @description:
 * @author: donghang
 * @date: 2020年8月20日上午11:50:55
 * @modify:
 */
public class FileProcessChain implements IFileProcessChain {
	private final List<IFileProcessFilter> additionalFilters;
	private final int size;
	private int currentPosition = 0;

	public FileProcessChain(List<IFileProcessFilter> additionalFilters) {
		this.additionalFilters = additionalFilters;
		this.size = additionalFilters.size();
	}

	/**
	 * 链式处理业务
	 * 
	 * @description:
	 * @param inputPath
	 * @return
	 * @author: donghang
	 * @date: 2020年8月20日上午11:51:47
	 * @modify:
	 */
	@Override
	public boolean doProcess(Map<String, Object> paraMap) throws Exception {
		if (currentPosition == size) {
			return true;
		} else {
			currentPosition++;
			IFileProcessFilter nextFilter = additionalFilters.get(currentPosition - 1);
			return nextFilter.doProcess(paraMap, this);
		}
	}
}
